import*as e from"../../../../core/common/common.js";import*as t from"../../../../core/i18n/i18n.js";import*as n from"../../legacy.js";import*as i from"../../../../core/root/root.js";import*as o from"../../../../core/host/host.js";import*as s from"../../../components/linear_memory_inspector/linear_memory_inspector.js";import*as r from"../../../../core/platform/platform.js";import*as a from"../../../../core/sdk/sdk.js";import*as l from"../../../../models/text_utils/text_utils.js";import*as c from"../../../../models/javascript_metadata/javascript_metadata.js";import*as p from"../../../components/icon_button/icon_button.js";import*as d from"../../../components/text_editor/text_editor.js";import*as h from"../../../../models/formatter/formatter.js";import*as u from"../../../../models/source_map_scopes/source_map_scopes.js";import*as m from"../utils/utils.js";const b={emptyD:"empty × {PH1}",empty:"empty",thePropertyIsComputedWithAGetter:"The property is computed with a getter"},v=t.i18n.registerUIStrings("ui/legacy/components/object_ui/RemoteObjectPreviewFormatter.ts",b),y=t.i18n.getLocalizedString.bind(void 0,v);class f{static objectPropertyComparator(e,t){return n(e)-n(t);function n(e){return"[[PromiseState]]"===e.name?1:"[[PromiseResult]]"===e.name?2:"[[GeneratorState]]"===e.name||"[[PrimitiveValue]]"===e.name||"[[WeakRefTarget]]"===e.name?3:"function"===e.type||e.name.startsWith("#")?5:4}}appendObjectPreview(e,t,i){const o=t.description,s=new Set(["arraybuffer","dataview","error","null","regexp","webassemblymemory","internal#entry","trustedtype"]);if("object"!==t.type||t.subtype&&s.has(t.subtype)||i)return void e.appendChild(this.renderPropertyPreview(t.type,t.subtype,void 0,o));const r="array"===t.subtype||"typedarray"===t.subtype;if(o){let n;if(r){const e=a.RemoteObject.RemoteObject.arrayLength(t),i=e>1?"("+e+")":"",s=a.RemoteObject.RemoteObject.arrayNameFromDescription(o);n="Array"===s?i:s+i}else{n="Object"===o?"":o}n.length>0&&(e.createChild("span","object-description").textContent=n+" ")}const l=e.createChild("span","object-properties-preview");if(n.UIUtils.createTextChild(l,r?"[":"{"),t.entries?this.appendEntriesPreview(l,t):r?this.appendArrayPropertiesPreview(l,t):this.appendObjectPropertiesPreview(l,t),t.overflow){const e=l.textContent&&l.textContent.length>1?", …":"…";l.createChild("span").textContent=e}n.UIUtils.createTextChild(l,r?"]":"}")}abbreviateFullQualifiedClassName(e){const t=e.split(".");for(let e=0;e<t.length-1;++e)t[e]=r.StringUtilities.trimMiddle(t[e],3);return t.join(".")}appendObjectPropertiesPreview(e,t){const i=t.properties.filter((e=>"accessor"!==e.type)).sort(f.objectPropertyComparator);for(let o=0;o<i.length;++o){o>0&&n.UIUtils.createTextChild(e,", ");const s=i[o],r=s.name;if("promise"===t.subtype&&"[[PromiseState]]"===r){e.appendChild(this.renderDisplayName("<"+s.value+">"));const t=o+1<i.length?i[o+1]:null;t&&"[[PromiseResult]]"===t.name&&("pending"!==s.value&&(n.UIUtils.createTextChild(e,": "),e.appendChild(this.renderPropertyPreviewOrAccessor([t]))),o++)}else"generator"===t.subtype&&"[[GeneratorState]]"===r?e.appendChild(this.renderDisplayName("<"+s.value+">")):"[[PrimitiveValue]]"===r?e.appendChild(this.renderPropertyPreviewOrAccessor([s])):"[[WeakRefTarget]]"===r?"undefined"===s.type?e.appendChild(this.renderDisplayName("<cleared>")):e.appendChild(this.renderPropertyPreviewOrAccessor([s])):(e.appendChild(this.renderDisplayName(r)),n.UIUtils.createTextChild(e,": "),e.appendChild(this.renderPropertyPreviewOrAccessor([s])))}}appendArrayPropertiesPreview(e,t){const i=a.RemoteObject.RemoteObject.arrayLength(t),o=t.properties.filter((e=>-1!==r(e.name))).sort((function(e,t){return r(e.name)-r(t.name)})),s=t.properties.filter((e=>-1===r(e.name))).sort(f.objectPropertyComparator);function r(e){const t=Number(e)>>>0;return String(t)===e&&t<i?t:-1}const l=!t.overflow;let c=-1,p=!1;for(let t=0;t<o.length;++t){p&&n.UIUtils.createTextChild(e,", ");const i=o[t],s=r(i.name);l&&s-c>1&&(d(s),n.UIUtils.createTextChild(e,", ")),l||t===s||(e.appendChild(this.renderDisplayName(i.name)),n.UIUtils.createTextChild(e,": ")),e.appendChild(this.renderPropertyPreviewOrAccessor([i])),c=s,p=!0}l&&i-c>1&&(p&&n.UIUtils.createTextChild(e,", "),d(i));for(let t=0;t<s.length;++t){p&&n.UIUtils.createTextChild(e,", ");const i=s[t];e.appendChild(this.renderDisplayName(i.name)),n.UIUtils.createTextChild(e,": "),e.appendChild(this.renderPropertyPreviewOrAccessor([i])),p=!0}function d(t){const n=e.createChild("span","object-value-undefined"),i=t-c-1;n.textContent=1!==i?y(b.emptyD,{PH1:i}):y(b.empty),p=!0}}appendEntriesPreview(e,t){if(t.entries)for(let i=0;i<t.entries.length;++i){i>0&&n.UIUtils.createTextChild(e,", ");const o=t.entries[i];o.key&&(this.appendObjectPreview(e,o.key,!0),n.UIUtils.createTextChild(e," => ")),this.appendObjectPreview(e,o.value,!0)}}renderDisplayName(e){const t=document.createElement("span");t.classList.add("name");const n=/^\s|\s$|^$|\n/.test(e);return t.textContent=n?'"'+e.replace(/\n/g,"↵")+'"':e,t}renderPropertyPreviewOrAccessor(e){const t=e[e.length-1];if(!t)throw new Error("Could not find property");return this.renderPropertyPreview(t.type,t.subtype,t.name,t.value)}renderPropertyPreview(e,t,i,o){const s=document.createElement("span");if(s.classList.add("object-value-"+(t||e)),o=o||"","accessor"===e)return s.textContent="(...)",n.Tooltip.Tooltip.install(s,y(b.thePropertyIsComputedWithAGetter)),s;if("function"===e)return s.textContent="ƒ",s;if("object"===e&&"trustedtype"===t&&i)return g(s,o,i),s;if("object"===e&&"node"===t&&o)return x(s,o),s;if("string"===e)return n.UIUtils.createTextChildren(s,r.StringUtilities.formatAsJSLiteral(o)),s;if("object"===e&&!t){let e=this.abbreviateFullQualifiedClassName(o);return"Object"===e&&(e="{…}"),s.textContent=e,n.Tooltip.Tooltip.install(s,o),s}return s.textContent=o,s}}const x=function(e,t){const n=t.match(/([^#.]+)(#[^.]+)?(\..*)?/);n&&(e.createChild("span","webkit-html-tag-name").textContent=n[1],n[2]&&(e.createChild("span","webkit-html-attribute-value").textContent=n[2]),n[3]&&(e.createChild("span","webkit-html-attribute-name").textContent=n[3]))},g=function(e,t,i){n.UIUtils.createTextChildren(e,`${i} `);const o=document.createElement("span");o.classList.add("object-value-string"),n.UIUtils.createTextChildren(o,'"',t.replace(/\n/g,"↵"),'"'),e.appendChild(o)};var w=Object.freeze({__proto__:null,RemoteObjectPreviewFormatter:f,createSpansForNodeTitle:x,createSpanForTrustedType:g});class E{static wrapObjectLiteral(e){const t=/^\s*\{\s*(.*)\s*\}[\s;]*$/.exec(e);if(null===t)return e;const[,n]=t;let i=0;for(const t of n)if("{"===t)i++;else if("}"===t&&--i<0)return e;const o=(async()=>0).constructor;try{o("return {"+n+"};");const e="({"+n+"})";return o(e),e}catch(t){return e}}static async evaluateAndBuildPreview(e,t,o,s,r,l,c=!1,p=!1){const d=n.Context.Context.instance().flavor(a.RuntimeModel.ExecutionContext),m=e.length>C;if(!e||!d||t&&m)return{preview:document.createDocumentFragment(),result:null};let b=e;if(i.Runtime.experiments.isEnabled("evaluateExpressionsWithSourceMaps")){const e=d.debuggerModel.selectedCallFrame();if(e){const t=await u.NamesResolver.allVariablesInCallFrame(e);try{b=await h.FormatterWorkerPool.formatterWorkerPool().javaScriptSubstitute(b,t)}catch{}}}b=E.wrapObjectLiteral(b);const v={expression:b,generatePreview:!0,includeCommandLineAPI:!0,throwOnSideEffect:t,timeout:s,objectGroup:l,disableBreaks:!0,replMode:o,silent:p},y=await d.evaluate(v,!1,c);return{preview:E.buildEvaluationPreview(y,r),result:y}}static buildEvaluationPreview(e,t){const n=document.createDocumentFragment();if("error"in e)return n;if(e.exceptionDetails&&e.exceptionDetails.exception&&e.exceptionDetails.exception.description){const i=e.exceptionDetails.exception.description;return(i.startsWith("TypeError: ")||t)&&(n.createChild("span").textContent=e.exceptionDetails.text+" "+i),n}const i=new f,{preview:o,type:s,subtype:a,className:l,description:c}=e.object;if(o&&"object"===s&&"node"!==a&&"trustedtype"!==a)i.appendObjectPreview(n,o,!1);else{const e=i.renderPropertyPreview(s,a,l,r.StringUtilities.trimEndWithMaxLength(c||"",400));n.appendChild(e)}return n}}let C=2e3;var j=Object.freeze({__proto__:null,JavaScriptREPL:E,setMaxLengthForEvaluation:function(e){C=e},getMaxLengthForEvaluation:function(){return C}});const P=new CSSStyleSheet;P.replaceSync(".value.object-value-node:hover{background-color:var(--item-hover-color)}.object-value-function-prefix,\n.object-value-boolean{color:var(--color-syntax-3)}.object-value-function{font-style:italic}.object-value-function.linkified:hover{--override-linkified-hover-background:rgb(0 0 0/10%);background-color:var(--override-linkified-hover-background);cursor:pointer}.-theme-with-dark-background .object-value-function.linkified:hover,\n:host-context(.-theme-with-dark-background) .object-value-function.linkified:hover{--override-linkified-hover-background:rgb(230 230 230/10%)}.object-value-number{color:var(--color-syntax-3)}.object-value-bigint{color:var(--color-syntax-6)}.object-value-string,\n.object-value-regexp,\n.object-value-symbol{white-space:pre;unicode-bidi:-webkit-isolate;color:var(--color-syntax-1)}.object-value-node{position:relative;vertical-align:baseline;color:var(--color-syntax-7);white-space:nowrap}.object-value-null,\n.object-value-undefined{color:var(--color-text-disabled)}.object-value-unavailable{color:var(--color-syntax-2)}.object-value-calculate-value-button:hover{text-decoration:underline}.object-properties-section-custom-section{display:inline-flex;flex-direction:column}.-theme-with-dark-background .object-value-number,\n:host-context(.-theme-with-dark-background) .object-value-number,\n.-theme-with-dark-background .object-value-boolean,\n:host-context(.-theme-with-dark-background) .object-value-boolean{--override-primitive-dark-mode-color:hsl(252deg 100% 75%);color:var(--override-primitive-dark-mode-color)}.object-properties-section .object-description{color:var(--color-text-secondary)}.value .object-properties-preview{white-space:nowrap}.name{color:var(--color-syntax-2);flex-shrink:0}.object-properties-preview .name{color:var(--color-text-secondary)}@media (forced-colors: active){.object-value-calculate-value-button:hover{forced-color-adjust:none;color:Highlight}}\n/*# sourceURL=objectValue.css */\n");const T=new CSSStyleSheet;T.replaceSync('.object-properties-section-dimmed{opacity:60%}.object-properties-section{padding:0;color:var(--color-text-primary);display:flex;flex-direction:column}.object-properties-section li{user-select:text}.object-properties-section li::before{top:-1px;margin-right:2px}.object-properties-section li.editing-sub-part{padding:3px 12px 8px 6px;margin:-1px -6px -8px;text-overflow:clip}.object-properties-section li.editing{margin-left:10px;text-overflow:clip}.tree-outline ol.title-less-mode{padding-left:0}.object-properties-section .own-property{font-weight:bold}.object-properties-section .synthetic-property{color:var(--color-text-secondary)}.object-properties-section .private-property-hash{color:var(--color-text-primary)}.object-properties-section-root-element{display:flex;flex-direction:row}.object-properties-section .editable-div{overflow:hidden}.object-properties-section [data-webidl="true"] > .name-and-value > .adorner{flex-shrink:0;width:16px;height:16px;margin-right:2px}.object-properties-section [data-webidl="true"] > .name-and-value > .name{font-weight:bold}.name-and-value{overflow:hidden;line-height:16px;display:flex;white-space:nowrap}.name-and-value .separator{white-space:pre;flex-shrink:0}.editing-sub-part .name-and-value{overflow:visible;display:inline-flex}.property-prompt{margin-left:4px}.tree-outline.hide-selection-when-blurred .selected:focus-visible{background:none}.tree-outline.hide-selection-when-blurred .selected:focus-visible ::slotted(*),\n.tree-outline.hide-selection-when-blurred .selected:focus-visible .tree-element-title,\n.tree-outline.hide-selection-when-blurred .selected:focus-visible .name-and-value,\n.tree-outline.hide-selection-when-blurred .selected:focus-visible .gray-info-message{background:var(--legacy-focus-bg-color);border-radius:2px;box-shadow:0 0 0 2px var(--legacy-focus-bg-color)}@media (forced-colors: active){.object-properties-section-dimmed{opacity:100%}.tree-outline.hide-selection-when-blurred .selected:focus-visible{background:Highlight}.tree-outline li:hover .tree-element-title,\n  .tree-outline li.selected .tree-element-title{color:ButtonText}.tree-outline.hide-selection-when-blurred .selected:focus-visible .tree-element-title,\n  .tree-outline.hide-selection-when-blurred .selected:focus-visible .name-and-value{background:transparent;box-shadow:none}.tree-outline.hide-selection-when-blurred .selected:focus-visible span,\n  .tree-outline.hide-selection-when-blurred .selected:focus-visible .gray-info-message{color:HighlightText}.tree-outline-disclosure:hover li.parent::before{background-color:ButtonText}}\n/*# sourceURL=objectPropertiesSection.css */\n');const I={exceptionS:"[Exception: {PH1}]",unknown:"unknown",expandRecursively:"Expand recursively",collapseChildren:"Collapse children",noProperties:"No properties",dots:"(...)",invokePropertyGetter:"Invoke property getter",showAllD:"Show all {PH1}",valueUnavailable:"<value unavailable>",valueNotAccessibleToTheDebugger:"Value is not accessible to the debugger",copyValue:"Copy value",copyPropertyPath:"Copy property path",stringIsTooLargeToEdit:"<string is too large to edit>",showMoreS:"Show more ({PH1})",longTextWasTruncatedS:"long text was truncated ({PH1})",copy:"Copy",revealInMemoryInpector:"Reveal in Memory Inspector panel"},O=t.i18n.registerUIStrings("ui/legacy/components/object_ui/ObjectPropertiesSection.ts",I),S=t.i18n.getLocalizedString.bind(void 0,O),L=new WeakMap,k=new WeakMap,M=c.JavaScriptMetadata.JavaScriptMetadataImpl.domPinnedProperties.DOMPinnedProperties;class R extends n.TreeOutline.TreeOutlineInShadow{object;editable;objectTreeElementInternal;titleElement;skipProtoInternal;constructor(e,t,n,i){super(),this.object=e,this.editable=!0,i||this.hideOverflow(),this.setFocusable(!0),this.setShowSelectionOnKeyboardFocus(!0),this.objectTreeElementInternal=new U(e,n),this.appendChild(this.objectTreeElementInternal),"string"!=typeof t&&t?(this.titleElement=t,this.element.appendChild(t)):(this.titleElement=this.element.createChild("span"),this.titleElement.textContent=t||""),this.titleElement instanceof HTMLElement&&!this.titleElement.hasAttribute("tabIndex")&&(this.titleElement.tabIndex=-1),k.set(this.element,this),this.registerCSSFiles([P,T]),this.rootElement().childrenListElement.classList.add("source-code","object-properties-section")}static defaultObjectPresentation(e,t,n,i){const o=R.defaultObjectPropertiesSection(e,t,n,i);return e.hasChildren?o.element:o.titleElement}static defaultObjectPropertiesSection(e,t,i,o){const s=document.createElement("span");s.classList.add("source-code");const r=n.Utils.createShadowRootWithCoreStyles(s,{cssFile:[P],delegatesFocus:void 0}),a=R.createPropertyValue(e,!1,!0);r.appendChild(a.element);const l=new R(e,s,t);return l.editable=!1,i&&l.skipProto(),o&&l.setEditable(!1),l}static assignWebIDLMetadata(e,t){if(!e)return;const n="object"===e.type&&null!==e.className?M[e.className]:void 0;if(!n)return;e.webIdl={info:n,state:new Map};const i=(n.includes?.map((e=>M[e]))??[]).flatMap((e=>Object.entries(e?.props??{}))),o={...n.props,...Object.fromEntries(i)};for(const e of t){const t=o[e.name];t&&(e.webIdl={info:t})}}static getPropertyValuesByNames(e){const t=new Map;for(const n of e)t.set(n.name,n.value);return t}static compareProperties(e,t){if(!e.synthetic&&t.synthetic)return 1;if(!t.synthetic&&e.synthetic)return-1;if(!e.isOwn&&t.isOwn)return 1;if(!t.isOwn&&e.isOwn)return-1;if(!e.enumerable&&t.enumerable)return 1;if(!t.enumerable&&e.enumerable)return-1;if(e.symbol&&!t.symbol)return 1;if(t.symbol&&!e.symbol)return-1;if(e.private&&!t.private)return 1;if(t.private&&!e.private)return-1;const n=e.name,i=t.name;return n.startsWith("_")&&!i.startsWith("_")?1:i.startsWith("_")&&!n.startsWith("_")?-1:r.StringUtilities.naturalOrderComparator(n,i)}static createNameElement(e,t){return null===e?n.Fragment.html`<span class="name"></span>`:/^\s|\s$|^$|\n/.test(e)?n.Fragment.html`<span class="name">"${e.replace(/\n/g,"↵")}"</span>`:t?n.Fragment.html`<span class="name"> <span class="private-property-hash">${e[0]}</span>${e.substring(1)} </span>`:n.Fragment.html`<span class="name">${e}</span>`}static valueElementForFunctionDescription(e,t,i){const o=document.createElement("span");o.classList.add("object-value-function");const s=(e=e||"").replace(/^function [gs]et /,"function ").replace(/^function [gs]et\(/,"function(").replace(/^[gs]et /,"");i=i||"";const a=s.match(/^(async\s+function)/),l=s.startsWith("function*"),c=s.startsWith("*"),p=!l&&s.startsWith("function"),d=s.startsWith("class ")||s.startsWith("class{"),h=s.indexOf("=>"),u=!a&&!l&&!p&&!d&&h>0;let m;if(d){m=s.substring("class".length);const e=/^[^{\s]+/.exec(m.trim());let t=i;e&&(t=e[0].trim()||i),v("class",m,t)}else if(a)m=s.substring(a[1].length),v("async ƒ",m,b(m));else if(l)m=s.substring("function*".length),v("ƒ*",m,b(m));else if(c)m=s.substring("*".length),v("ƒ*",m,b(m));else if(p)m=s.substring("function".length),v("ƒ",m,b(m));else if(u){const e=60;let t=s;i?t=i+"()":s.length>e&&(t=s.substring(0,h+2)+" {…}"),v("",s,t)}else v("ƒ",s,b(s));return n.Tooltip.Tooltip.install(o,r.StringUtilities.trimEndWithMaxLength(e,500)),o;function b(e){const t=e.indexOf("("),n=e.match(/\)\s*{/);if(-1!==t&&n&&void 0!==n.index&&n.index>t){return(e.substring(0,t).trim()||i)+e.substring(t,n.index+1)}return i+"()"}function v(e,i,s){e.length&&(o.createChild("span","object-value-function-prefix").textContent=e+" "),t?n.UIUtils.createTextChild(o,r.StringUtilities.trimEndWithMaxLength(i.trim(),200)):n.UIUtils.createTextChild(o,s.replace(/\n/g," "))}}static createPropertyValueWithCustomSupport(e,t,n,i,o,s,r){if(e.customPreview()){const t=new q(e).element;return t.classList.add("object-properties-section-custom-section"),new B(t)}return R.createPropertyValue(e,t,n,i,o,s,r)}static appendMemoryIcon(e,t,i){if(!("object"===t.type&&t.subtype&&s.LinearMemoryInspectorController.ACCEPTED_MEMORY_TYPES.includes(t.subtype))&&!s.LinearMemoryInspectorController.isDWARFMemoryObject(t))return;const r=new p.Icon.Icon;r.data={iconName:"memory",color:"var(--icon-default)",width:"16px",height:"13px"},r.onclick=async e=>{e.stopPropagation();const n=s.LinearMemoryInspectorController.LinearMemoryInspectorController.instance();o.userMetrics.linearMemoryInspectorRevealedFrom(o.UserMetrics.LinearMemoryInspectorRevealedFrom.MemoryIcon),n.openInspectorView(t,void 0,i)};const a=S(I.revealInMemoryInpector);n.Tooltip.Tooltip.install(r,a),n.ARIAUtils.setLabel(r,a),r.style.setProperty("vertical-align","sub"),r.style.setProperty("cursor","pointer"),e.appendChild(r)}static createPropertyValue(i,o,s,l,c,p=!1,d){let h;const u=i.type,m=i.subtype,b=i.description||"",v=i.className;if("object"===u&&"internal#location"===m){const e=i.debuggerModel().createRawLocationByScriptId(i.value.scriptId,i.value.lineNumber,i.value.columnNumber);if(e&&c)return new B(c.linkifyRawLocation(e,r.DevToolsPath.EmptyUrlString));h=new B(function(){const e=document.createElement("span");return e.textContent="<"+S(I.unknown)+">",n.Tooltip.Tooltip.install(e,b||""),e}())}else if("string"===u&&"string"==typeof b)h=y();else if("object"===u&&"trustedtype"===m)h=function(){const e=document.createElement("span");e.classList.add("object-value-trustedtype");const t=`${v} "${b}"`;let i;if(t.length>A)i=new J(e,t,50);else{const o=y();n.UIUtils.createTextChild(e,`${v} `),e.appendChild(o.element),i=new B(e),n.Tooltip.Tooltip.install(e,t)}return i}();else if("function"===u)h=new B(R.valueElementForFunctionDescription(b));else if("object"===u&&"node"===m&&b)h=new B(function(){const t=document.createElement("span");return t.classList.add("object-value-node"),x(t,b),t.addEventListener("click",(t=>{e.Revealer.reveal(i),t.consume(!0)}),!1),t.addEventListener("mousemove",(()=>a.OverlayModel.OverlayModel.highlightObjectAsDOMNode(i)),!1),t.addEventListener("mouseleave",(()=>a.OverlayModel.OverlayModel.hideDOMNodeHighlight()),!1),t}());else{const e=document.createElement("span");if(e.classList.add("object-value-"+(m||u)),i.preview&&s){(new f).appendObjectPreview(e,i.preview,!1),h=new B(e),n.Tooltip.Tooltip.install(h.element,b||"")}else b.length>A?h=new J(e,b,50):(h=new B(e),h.element.textContent=b,n.Tooltip.Tooltip.install(h.element,b));p||this.appendMemoryIcon(e,i,d)}if(o){const e=document.createElement("span");e.classList.add("error"),e.classList.add("value"),e.appendChild(t.i18n.getFormatLocalizedString(O,I.exceptionS,{PH1:h.element})),h.element=e}return h.element.classList.add("value"),h;function y(){const e=document.createElement("span");e.classList.add("object-value-string");const t=JSON.stringify(b);let i;return b.length>A?i=new J(e,t,50):(n.UIUtils.createTextChild(e,t),i=new B(e),n.Tooltip.Tooltip.install(e,b)),i}}static formatObjectAsFunction(t,n,i,o){return t.debuggerModel().functionDetailsPromise(t).then((function(s){i&&s&&s.location&&(n.classList.add("linkified"),n.addEventListener("click",(()=>(e.Revealer.reveal(s.location),!1))));let r=o?"":"anonymous";s&&s.functionName&&(r=s.functionName);const a=R.valueElementForFunctionDescription(t.description,o,r);n.appendChild(a)}))}static isDisplayableProperty(e,t){if(!t||!t.synthetic)return!0;const n=e.name;return!("[[Entries]]"===t.name&&("length"===n||"__proto__"===n))}skipProto(){this.skipProtoInternal=!0}expand(){this.objectTreeElementInternal.expand()}setEditable(e){this.editable=e}objectTreeElement(){return this.objectTreeElementInternal}enableContextMenu(){this.element.addEventListener("contextmenu",this.contextMenuEventFired.bind(this),!1)}contextMenuEventFired(e){const t=new n.ContextMenu.ContextMenu(e);t.appendApplicableItems(this.object),this.object instanceof a.RemoteObject.LocalJSONObject&&(t.viewSection().appendItem(S(I.expandRecursively),this.objectTreeElementInternal.expandRecursively.bind(this.objectTreeElementInternal,100)),t.viewSection().appendItem(S(I.collapseChildren),this.objectTreeElementInternal.collapseChildren.bind(this.objectTreeElementInternal))),t.show()}titleLessMode(){this.objectTreeElementInternal.listItemElement.classList.add("hidden"),this.objectTreeElementInternal.childrenListElement.classList.add("title-less-mode"),this.objectTreeElementInternal.expand()}}let A=1e4;class N extends n.TreeOutline.TreeOutlineInShadow{editable;constructor(e){super(),this.registerCSSFiles([P,T]),this.editable=!(e&&e.readOnly),this.contentElement.classList.add("source-code"),this.contentElement.classList.add("object-properties-section"),this.hideOverflow()}}class U extends n.TreeOutline.TreeElement{object;linkifier;emptyPlaceholder;propertiesMode;extraProperties;targetObject;toggleOnClick;constructor(e,t,n,i=1,o=[],s=e){super(document.createElement("slot")),this.object=e,this.linkifier=t,this.emptyPlaceholder=n,this.propertiesMode=i,this.extraProperties=o,this.targetObject=s,this.setExpandable(!0),this.selectable=!0,this.toggleOnClick=!0,this.listItemElement.classList.add("object-properties-section-root-element"),this.listItemElement.addEventListener("contextmenu",this.onContextMenu.bind(this),!1)}onexpand(){this.treeOutline&&this.treeOutline.element.classList.add("expanded")}oncollapse(){this.treeOutline&&this.treeOutline.element.classList.remove("expanded")}ondblclick(e){return!0}onContextMenu(e){const t=new n.ContextMenu.ContextMenu(e);if(t.appendApplicableItems(this.object),this.object instanceof a.RemoteObject.LocalJSONObject){const{value:e}=this.object,n="object"==typeof e?JSON.stringify(e,null,2):e,i=()=>{o.userMetrics.actionTaken(o.UserMetrics.Action.NetworkPanelCopyValue),o.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(n)};t.clipboardSection().appendItem(S(I.copyValue),i)}t.viewSection().appendItem(S(I.expandRecursively),this.expandRecursively.bind(this,100)),t.viewSection().appendItem(S(I.collapseChildren),this.collapseChildren.bind(this)),t.show()}async onpopulate(){const e=this.treeOutline,t=!!e&&Boolean(e.skipProtoInternal);return F.populate(this,this.object,t,!1,this.linkifier,this.emptyPlaceholder,this.propertiesMode,this.extraProperties,this.targetObject)}}class F extends n.TreeOutline.TreeElement{property;toggleOnClick;highlightChanges;linkifier;maxNumPropertiesToShow;nameElement;valueElement;rowContainer;readOnly;prompt;editableDiv;propertyValue;expandedValueElement;constructor(e,t){super(),this.property=e,this.toggleOnClick=!0,this.highlightChanges=[],this.linkifier=t,this.maxNumPropertiesToShow=200,this.listItemElement.addEventListener("contextmenu",this.contextMenuFired.bind(this),!1),this.listItemElement.dataset.objectPropertyNameForTest=e.name,this.setExpandRecursively("[[Prototype]]"!==e.name)}static async populate(e,t,n,i,o,s,r=1,l,c){if(t.arrayLength()>100)return e.removeChildren(),void D.populateArray(e,t,0,t.arrayLength()-1,o);let p,d=null;switch(r){case 0:({properties:p}=await t.getAllProperties(!1,!0));break;case 1:({properties:p,internalProperties:d}=await a.RemoteObject.RemoteObject.loadFromObjectPerProto(t,!0))}e.removeChildren(),p&&(void 0!==l&&p.push(...l),F.populateWithProperties(e,p,d,n,i,c||t,o,s))}static populateWithProperties(e,t,n,i,o,s,r,l){R.assignWebIDLMetadata(s,t);const c=R.getPropertyValuesByNames(t);if(s?.webIdl){const e=s.webIdl.info.rules;if(e)for(const{when:t,is:n}of e)c.get(t)?.value===n&&s.webIdl.state.set(t,n);for(const n of t)if(n.webIdl){const t=s.webIdl.state,i=n.webIdl.info.rules;n.webIdl.applicable=!e&&!i||(!i||i?.some((e=>t.get(e.when)===e.is)))}}t.sort(R.compareProperties);const p=(n=n||[]).find((e=>"[[Entries]]"===e.name));if(p){L.set(p,s);const t=new F(p,r);t.setExpandable(!0),t.expand(),e.appendChild(t)}const d=[];for(let n=0;n<t.length;++n){const i=t[n];if(L.set(i,s),!R.isDisplayableProperty(i,e.property))continue;if(i.isOwn&&!o){if(i.getter){const e=new a.RemoteObject.RemoteObjectProperty("get "+i.name,i.getter,!1);L.set(e,s),d.push(e)}if(i.setter){const e=new a.RemoteObject.RemoteObjectProperty("set "+i.name,i.setter,!1);L.set(e,s),d.push(e)}}if(i.getter||!i.isAccessorProperty()){const t=new F(i,r);"memories"===i.name&&"Memories"===i.value?.className&&(t.updateExpandable(),t.isExpandable()&&t.expand()),e.appendChild(t)}}for(let t=0;t<d.length;++t)e.appendChild(new F(d[t],r));for(const t of n){L.set(t,s);const n=new F(t,r);"[[Entries]]"!==t.name&&("[[Prototype]]"===t.name&&i||e.appendChild(n))}F.appendEmptyPlaceholderIfNeeded(e,l)}static appendEmptyPlaceholderIfNeeded(e,t){if(e.childCount())return;const i=document.createElement("div");i.classList.add("gray-info-message"),i.textContent=t||S(I.noProperties);const o=new n.TreeOutline.TreeElement(i);e.appendChild(o)}static createRemoteObjectAccessorPropertySpan(e,t,i){const o=document.createElement("span"),s=o.createChild("span");if(s.textContent=S(I.dots),!e)return o;function r(e){let t=this;const n=JSON.parse(e);for(let e=0,i=n.length;e<i;++e)t=t[n[e]];return t}return s.classList.add("object-value-calculate-value-button"),n.Tooltip.Tooltip.install(s,S(I.invokePropertyGetter)),s.addEventListener("click",(function(n){n.consume(),e&&e.callFunction(r,[{value:JSON.stringify(t)}]).then(i)}),!1),o}setSearchRegex(e,t){let i=n.UIUtils.highlightedSearchResultClassName;if(t&&(i+=" "+t),this.revertHighlightChanges(),this.applySearch(e,this.nameElement,i),this.property.value){"object"!==this.property.value.type&&this.applySearch(e,this.valueElement,i)}return Boolean(this.highlightChanges.length)}applySearch(e,t,i){const o=[],s=t.textContent||"";e.lastIndex=0;let r=e.exec(s);for(;r;)o.push(new l.TextRange.SourceRange(r.index,r[0].length)),r=e.exec(s);o.length&&n.UIUtils.highlightRangesWithStyleClass(t,o,i,this.highlightChanges)}showAllPropertiesElementSelected(e){return this.removeChild(e),this.children().forEach((e=>{e.hidden=!1})),!1}createShowAllPropertiesButton(){const e=document.createElement("div");e.classList.add("object-value-calculate-value-button"),e.textContent=S(I.dots),n.Tooltip.Tooltip.install(e,S(I.showAllD,{PH1:this.childCount()}));const t=this.children();for(let e=this.maxNumPropertiesToShow;e<this.childCount();++e)t[e].hidden=!0;const i=new n.TreeOutline.TreeElement(e);i.onselect=this.showAllPropertiesElementSelected.bind(this,i),this.appendChild(i)}revertHighlightChanges(){n.UIUtils.revertDomChanges(this.highlightChanges),this.highlightChanges=[]}async onpopulate(){const e=this.property.value;console.assert(void 0!==e);const t=this.treeOutline,n=!!t&&Boolean(t.skipProtoInternal),i="[[Prototype]]"!==this.property.name?e:L.get(this.property);i&&(await F.populate(this,e,n,!1,this.linkifier,void 0,void 0,void 0,i),this.childCount()>this.maxNumPropertiesToShow&&this.createShowAllPropertiesButton())}ondblclick(e){const t=e.target,n=t.isSelfOrDescendant(this.valueElement)||this.expandedValueElement&&t.isSelfOrDescendant(this.expandedValueElement);return this.property.value&&!this.property.value.customPreview()&&n&&(this.property.writable||this.property.setter)&&this.startEditing(),!1}onenter(){return!(!this.property.value||this.property.value.customPreview()||!this.property.writable&&!this.property.setter)&&(this.startEditing(),!0)}onattach(){this.update(),this.updateExpandable()}onexpand(){this.showExpandedValueElement(!0)}oncollapse(){this.showExpandedValueElement(!1)}showExpandedValueElement(e){this.expandedValueElement&&(e?this.rowContainer.replaceChild(this.expandedValueElement,this.valueElement):this.rowContainer.replaceChild(this.valueElement,this.expandedValueElement))}createExpandedValueElement(e,t){if(!(e.hasChildren&&!e.customPreview()&&"node"!==e.subtype&&"function"!==e.type&&("object"!==e.type||e.preview)))return null;const i=document.createElement("span");return i.classList.add("value"),"Object"===e.description?i.textContent="":i.setTextContentTruncatedIfNeeded(e.description||""),i.classList.add("object-value-"+(e.subtype||e.type)),n.Tooltip.Tooltip.install(i,e.description||""),t||R.appendMemoryIcon(i,e),i}update(){this.nameElement=R.createNameElement(this.property.name,this.property.private),this.property.enumerable||this.nameElement.classList.add("object-properties-section-dimmed"),this.property.isOwn&&this.nameElement.classList.add("own-property"),this.property.synthetic&&this.nameElement.classList.add("synthetic-property"),this.updatePropertyPath();const e=this.property.synthetic&&"[[Entries]]"===this.property.name;if(e)this.valueElement=document.createElement("span"),this.valueElement.classList.add("value");else if(this.property.value){const e="[[Prototype]]"!==this.property.name;this.propertyValue=R.createPropertyValueWithCustomSupport(this.property.value,this.property.wasThrown,e,this.listItemElement,this.linkifier,this.property.synthetic,this.path()),this.valueElement=this.propertyValue.element}else if(this.property.getter){this.valueElement=document.createElement("span");const e=this.valueElement.createChild("span");e.textContent=S(I.dots),e.classList.add("object-value-calculate-value-button"),n.Tooltip.Tooltip.install(e,S(I.invokePropertyGetter));const t=L.get(this.property),i=this.property.getter;e.addEventListener("click",(e=>{e.consume();t.callFunction("\n          function invokeGetter(getter) {\n            return Reflect.apply(getter, this, []);\n          }",[a.RemoteObject.RemoteObject.toCallArgument(i)]).then(this.onInvokeGetterClick.bind(this))}),!1)}else this.valueElement=document.createElement("span"),this.valueElement.classList.add("object-value-unavailable"),this.valueElement.textContent=S(I.valueUnavailable),n.Tooltip.Tooltip.install(this.valueElement,S(I.valueNotAccessibleToTheDebugger));const t=this.valueElement.textContent;this.property.value&&t&&!this.property.wasThrown&&(this.expandedValueElement=this.createExpandedValueElement(this.property.value,this.property.synthetic));const o=i.Runtime.experiments.isEnabled(i.Runtime.ExperimentName.IMPORTANT_DOM_PROPERTIES);let s,r="";if(this.property.webIdl?.applicable&&o){const e=new p.Icon.Icon;e.data={iconName:"star",color:"var(--icon-default)",width:"16px",height:"16px"},r=n.Fragment.html` <span class="adorner">${e}</span> `}s=e?n.Fragment.html` <span class="name-and-value">${r}${this.nameElement}</span> `:n.Fragment.html` <span class="name-and-value">${r}${this.nameElement}<span class="separator">: </span>${this.valueElement}</span> `,this.listItemElement.removeChildren(),this.rowContainer=s,this.listItemElement.appendChild(this.rowContainer),o&&(this.listItemElement.dataset.webidl=this.property.webIdl?.applicable?"true":"false")}updatePropertyPath(){if(this.nameElement.title)return;const e=this.property.name;if(this.property.synthetic)return void n.Tooltip.Tooltip.install(this.nameElement,e);const t=this.parent instanceof F&&this.parent.nameElement&&!this.parent.property.synthetic?this.parent.nameElement.title:"";this.property.private||/^(?:[$_\p{ID_Start}])(?:[$_\u200C\u200D\p{ID_Continue}])*$/u.test(e)?n.Tooltip.Tooltip.install(this.nameElement,t?`${t}.${e}`:e):/^(?:0|[1-9]\d*)$/.test(e)?n.Tooltip.Tooltip.install(this.nameElement,`${t}[${e}]`):n.Tooltip.Tooltip.install(this.nameElement,`${t}[${JSON.stringify(e)}]`)}contextMenuFired(e){const t=new n.ContextMenu.ContextMenu(e);if(t.appendApplicableItems(this),this.property.symbol&&t.appendApplicableItems(this.property.symbol),this.property.value&&(t.appendApplicableItems(this.property.value),L.get(this.property)instanceof a.RemoteObject.LocalJSONObject)){const{value:{value:e}}=this.property,n="object"==typeof e?JSON.stringify(e,null,2):e,i=()=>{o.userMetrics.actionTaken(o.UserMetrics.Action.NetworkPanelCopyValue),o.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(n)};t.clipboardSection().appendItem(S(I.copyValue),i)}if(!this.property.synthetic&&this.nameElement&&this.nameElement.title){const e=o.InspectorFrontendHost.InspectorFrontendHostInstance.copyText.bind(o.InspectorFrontendHost.InspectorFrontendHostInstance,this.nameElement.title);t.clipboardSection().appendItem(S(I.copyPropertyPath),e)}L.get(this.property)instanceof a.RemoteObject.LocalJSONObject&&(t.viewSection().appendItem(S(I.expandRecursively),this.expandRecursively.bind(this,100)),t.viewSection().appendItem(S(I.collapseChildren),this.collapseChildren.bind(this))),this.propertyValue&&this.propertyValue.appendApplicableItems(e,t,{}),t.show()}startEditing(){const e=this.treeOutline;if(this.prompt||!e||!e.editable||this.readOnly)return;if(this.editableDiv=this.rowContainer.createChild("span","editable-div"),this.property.value){let e=this.property.value.description;"string"===this.property.value.type&&"string"==typeof e&&(e=`"${e}"`),this.editableDiv.setTextContentTruncatedIfNeeded(e,S(I.stringIsTooLargeToEdit))}const t=this.editableDiv.textContent||"";this.setExpandable(!1),this.listItemElement.classList.add("editing-sub-part"),this.valueElement.classList.add("hidden"),this.prompt=new _;const n=this.prompt.attachAndStartEditing(this.editableDiv,this.editingCommitted.bind(this,t));n.classList.add("property-prompt");const i=this.listItemElement.getComponentSelection();i&&i.selectAllChildren(this.editableDiv),n.addEventListener("keydown",this.promptKeyDown.bind(this,t),!1)}editingEnded(){this.prompt&&(this.prompt.detach(),delete this.prompt),this.editableDiv.remove(),this.updateExpandable(),this.listItemElement.scrollLeft=0,this.listItemElement.classList.remove("editing-sub-part"),this.select()}editingCancelled(){this.valueElement.classList.remove("hidden"),this.editingEnded()}async editingCommitted(e){const t=this.prompt?this.prompt.text():"";t!==e?(this.editingEnded(),await this.applyExpression(t)):this.editingCancelled()}promptKeyDown(e,t){const n=t;return"Enter"===n.key?(n.consume(),void this.editingCommitted(e)):n.key===r.KeyboardUtilities.ESCAPE_KEY?(n.consume(),void this.editingCancelled()):void 0}async applyExpression(e){const t=a.RemoteObject.RemoteObject.toCallArgument(this.property.symbol||this.property.name);if(e=E.wrapObjectLiteral(e.trim()),this.property.synthetic){let t=!1;if(e&&(t=await this.property.setSyntheticValue(e)),t){const e=this.parent;e&&(e.invalidateChildren(),e.onpopulate())}else this.update();return}const n=L.get(this.property),i=e?n.setPropertyValue(t,e):n.deleteProperty(t);if(await i)this.update();else if(e){const e=this.parent;e&&(e.invalidateChildren(),e.onpopulate())}else this.parent&&this.parent.removeChild(this)}onInvokeGetterClick(e){e.object&&(this.property.value=e.object,this.property.wasThrown=e.wasThrown||!1,this.update(),this.invalidateChildren(),this.updateExpandable())}updateExpandable(){this.property.value?this.setExpandable(!this.property.value.customPreview()&&this.property.value.hasChildren&&!this.property.wasThrown):this.setExpandable(!1)}path(){return this.nameElement.title}}class D extends n.TreeOutline.TreeElement{toggleOnClick;fromIndex;toIndex;object;readOnly;propertyCount;linkifier;constructor(e,t,n,i,o){super(r.StringUtilities.sprintf("[%d … %d]",t,n),!0),this.toggleOnClick=!0,this.fromIndex=t,this.toIndex=n,this.object=e,this.readOnly=!0,this.propertyCount=i,this.linkifier=o}static async populateArray(e,t,n,i,o){await D.populateRanges(e,t,n,i,!0,o)}static async populateRanges(e,t,n,i,o,s){const r=await t.callFunctionJSON((function(e,t,n,i){if(void 0===e||void 0===t||void 0===i||void 0===n)return;let o=null;const s=t-e>=i&&ArrayBuffer.isView(this);function*r(n){if(void 0!==e&&void 0!==t&&void 0!==i)if(t-e<i)for(let i=e;i<=t;++i)i in n&&(yield i);else{o=o||Object.getOwnPropertyNames(n);for(let n=0;n<o.length;++n){const i=o[n],s=Number(i)>>>0;String(s)===i&&e<=s&&s<=t&&(yield s)}}}let a=0;if(s)a=t-e+1;else for(const e of r(this))++a;let l=a;l=a<=n?a:Math.pow(n,Math.ceil(Math.log(a)/Math.log(n))-1);const c=[];if(s)for(let n=e;n<=t;n+=l){const e=n;let i=e+l-1;i>t&&(i=t),c.push([e,i,i-e+1])}else{a=0;let e=-1,t=0;for(const n of r(this))-1===e&&(e=n),t=n,++a===l&&(c.push([e,t,a]),a=0,e=-1);a>0&&c.push([e,t,a])}return{ranges:c}}),[{value:n},{value:i},{value:D.bucketThreshold},{value:D.sparseIterationThreshold}]);await async function(n){if(!n)return;const i=n.ranges;if(1===i.length)await D.populateAsFragment(e,t,i[0][0],i[0][1],s);else for(let n=0;n<i.length;++n){const o=i[n][0],r=i[n][1],a=i[n][2];o===r?await D.populateAsFragment(e,t,o,r,s):e.appendChild(new D(t,o,r,a,s))}o&&await D.populateNonIndexProperties(e,t,s)}(r)}static async populateAsFragment(e,t,n,i,o){const s=await t.callFunction((function(e,t,n){const i=Object.create(null);if(void 0===e||void 0===t||void 0===n)return;if(t-e<n)for(let n=e;n<=t;++n)n in this&&(i[n]=this[n]);else{const n=Object.getOwnPropertyNames(this);for(let o=0;o<n.length;++o){const s=n[o],r=Number(s)>>>0;String(r)===s&&e<=r&&r<=t&&(i[r]=this[r])}}return i}),[{value:n},{value:i},{value:D.sparseIterationThreshold}]);if(!s.object||s.wasThrown)return;const r=s.object,a=await r.getAllProperties(!1,!0);r.release();const l=a.properties;if(l){l.sort(R.compareProperties);for(let t=0;t<l.length;++t){L.set(l[t],this.object);const n=new F(l[t],o);n.readOnly=!0,e.appendChild(n)}}}static async populateNonIndexProperties(e,t,n){const{properties:i,internalProperties:o}=await a.RemoteObject.RemoteObject.loadFromObjectPerProto(t,!0,!0);i&&F.populateWithProperties(e,i,o,!1,!1,t,n)}async onpopulate(){this.propertyCount>=D.bucketThreshold?await D.populateRanges(this,this.object,this.fromIndex,this.toIndex,!1,this.linkifier):await D.populateAsFragment(this,this.object,this.fromIndex,this.toIndex,this.linkifier)}onattach(){this.listItemElement.classList.add("object-properties-section-name")}static bucketThreshold=100;static sparseIterationThreshold=25e4}class _ extends n.TextPrompt.TextPrompt{constructor(){super(),this.initialize(d.JavaScript.completeInContext)}}const V=new Map,W=new Map;let H;class ${static instance(e={forceNew:!1}){const{forceNew:t}=e;return H&&!t||(H=new $),H}async render(e,t){if(!(e instanceof a.RemoteObject.RemoteObject))throw new Error("Can't render "+e);const n=(t=t||{title:void 0,editable:void 0}).title,i=new R(e,n);return n||i.titleLessMode(),i.editable=Boolean(t.editable),{node:i.element,tree:i}}}class B{element;constructor(e){this.element=e}appendApplicableItems(e,t,n){}}class J extends B{text;maxLength;expandElement;maxDisplayableTextLength;expandElementText;copyButtonText;constructor(e,t,i){super(e);const o=e.createChild("span");this.text=t,this.maxLength=i,o.textContent=t.slice(0,i),n.Tooltip.Tooltip.install(o,`${t.slice(0,i)}…`),this.expandElement=o.createChild("span"),this.maxDisplayableTextLength=1e7;const s=r.StringUtilities.countWtf8Bytes(t),a=r.NumberUtilities.bytesToString(s);this.text.length<this.maxDisplayableTextLength?(this.expandElementText=S(I.showMoreS,{PH1:a}),this.expandElement.setAttribute("data-text",this.expandElementText),this.expandElement.classList.add("expandable-inline-button"),this.expandElement.addEventListener("click",this.expandText.bind(this)),this.expandElement.addEventListener("keydown",(e=>{const t=e;"Enter"!==t.key&&" "!==t.key||this.expandText()})),n.ARIAUtils.markAsButton(this.expandElement)):(this.expandElement.setAttribute("data-text",S(I.longTextWasTruncatedS,{PH1:a})),this.expandElement.classList.add("undisplayable-text")),this.copyButtonText=S(I.copy);const l=o.createChild("span","expandable-inline-button");l.setAttribute("data-text",this.copyButtonText),l.addEventListener("click",this.copyText.bind(this)),l.addEventListener("keydown",(e=>{const t=e;"Enter"!==t.key&&" "!==t.key||this.copyText()})),n.ARIAUtils.markAsButton(l)}appendApplicableItems(e,t,n){this.text.length<this.maxDisplayableTextLength&&this.expandElement&&t.clipboardSection().appendItem(this.expandElementText||"",this.expandText.bind(this)),t.clipboardSection().appendItem(this.copyButtonText,this.copyText.bind(this))}expandText(){this.expandElement&&(this.expandElement.parentElement&&this.expandElement.parentElement.insertBefore(document.createTextNode(this.text.slice(this.maxLength)),this.expandElement),this.expandElement.remove(),this.expandElement=null)}copyText(){o.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(this.text)}}var G=Object.freeze({__proto__:null,getObjectPropertiesSectionFrom:e=>k.get(e),ObjectPropertiesSection:R,setMaxRenderableStringLength:function(e){A=e},getMaxRenderableStringLength:function(){return A},ObjectPropertiesSectionsTreeOutline:N,RootElement:U,InitialVisibleChildrenLimit:200,ObjectPropertyTreeElement:F,ArrayGroupingTreeElement:D,ObjectPropertyPrompt:_,ObjectPropertiesSectionsTreeExpandController:class{expandedProperties;constructor(e){this.expandedProperties=new Set,e.addEventListener(n.TreeOutline.Events.ElementAttached,this.elementAttached,this),e.addEventListener(n.TreeOutline.Events.ElementExpanded,this.elementExpanded,this),e.addEventListener(n.TreeOutline.Events.ElementCollapsed,this.elementCollapsed,this)}watchSection(e,t){V.set(t,e),this.expandedProperties.has(e)&&t.expand()}stopWatchSectionsWithId(e){for(const t of this.expandedProperties)t.startsWith(e+":")&&this.expandedProperties.delete(t)}elementAttached(e){const t=e.data;t.isExpandable()&&this.expandedProperties.has(this.propertyPath(t))&&t.expand()}elementExpanded(e){const t=e.data;this.expandedProperties.add(this.propertyPath(t))}elementCollapsed(e){const t=e.data;this.expandedProperties.delete(this.propertyPath(t))}propertyPath(e){const t=W.get(e);if(t)return t;let n=e,i=n;if(!e.treeOutline)throw new Error("No tree outline available");const o=e.treeOutline.rootElement();let s;for(;n!==o;){let e="";e=n.property?n.property.name:"string"==typeof n.title?n.title:n.title.textContent||"",s=e+(s?"."+s:""),i=n,n.parent&&(n=n.parent)}return s=V.get(i)+(s?":"+s:""),W.set(e,s),s}},Renderer:$,ObjectPropertyValue:B,ExpandableTextPropertyValue:J});const z=new CSSStyleSheet;z.replaceSync(".custom-expandable-section{display:inline-flex;flex-direction:column}.custom-expand-icon{user-select:none;margin-right:4px;margin-bottom:-4px}.custom-expandable-section-standard-section{display:inline-flex}\n/*# sourceURL=customPreviewComponent.css */\n");const K={showAsJavascriptObject:"Show as JavaScript object"},Y=t.i18n.registerUIStrings("ui/legacy/components/object_ui/CustomPreviewComponent.ts",K),Q=t.i18n.getLocalizedString.bind(void 0,Y);class X{sectionElement;object;expanded;cachedContent;header;expandIcon;constructor(t){this.sectionElement=document.createElement("span"),this.sectionElement.classList.add("custom-expandable-section"),this.object=t,this.expanded=!1,this.cachedContent=null;const i=t.customPreview();if(!i)return;let o;try{o=JSON.parse(i.header)}catch(t){return void e.Console.Console.instance().error("Broken formatter: header is invalid json "+t)}this.header=this.renderJSONMLTag(o),this.header.nodeType!==Node.TEXT_NODE?(i.bodyGetterId&&(this.header instanceof Element&&this.header.classList.add("custom-expandable-section-header"),this.header.addEventListener("click",this.onClick.bind(this),!1),this.expandIcon=n.Icon.Icon.create("triangle-right","custom-expand-icon"),this.header.insertBefore(this.expandIcon,this.header.firstChild)),this.sectionElement.appendChild(this.header)):e.Console.Console.instance().error("Broken formatter: header should be an element node.")}element(){return this.sectionElement}renderJSONMLTag(e){if(!Array.isArray(e))return document.createTextNode(String(e));const t=e;return"object"===t[0]?this.layoutObjectTag(t):this.renderElement(t)}renderElement(t){const n=t.shift();if(!X.allowedTags.has(n))return e.Console.Console.instance().error("Broken formatter: element "+n+" is not allowed!"),document.createElement("span");const i=document.createElement(n);if("object"==typeof t[0]&&!Array.isArray(t[0])){const e=t.shift();for(const t in e){const n=e[t];"style"===t&&"string"==typeof n&&i.setAttribute(t,n)}}return this.appendJsonMLTags(i,t),i}layoutObjectTag(e){e.shift();const t=e.shift(),n=this.object.runtimeModel().createRemoteObject(t);if(n.customPreview())return new X(n).element();const i=R.defaultObjectPresentation(n);return i.classList.toggle("custom-expandable-section-standard-section",n.hasChildren),i}appendJsonMLTags(e,t){for(let n=0;n<t.length;++n)e.appendChild(this.renderJSONMLTag(t[n]))}onClick(e){e.consume(!0),this.cachedContent?this.toggleExpand():this.loadBody()}toggleExpand(){this.expanded=!this.expanded,this.header instanceof Element&&this.header.classList.toggle("expanded",this.expanded),this.cachedContent instanceof Element&&this.cachedContent.classList.toggle("hidden",!this.expanded),this.expandIcon&&(this.expanded?this.expandIcon.setIconType("triangle-down"):this.expandIcon.setIconType("triangle-right"))}async loadBody(){const e=this.object.customPreview();if(e&&e.bodyGetterId){const t=await this.object.callFunctionJSON((e=>e()),[{objectId:e.bodyGetterId}]);if(!t)return;this.cachedContent=this.renderJSONMLTag(t),this.sectionElement.appendChild(this.cachedContent),this.toggleExpand()}}static allowedTags=new Set(["span","div","ol","li","table","tr","td"])}class q{object;customPreviewSection;element;constructor(e){this.object=e,this.customPreviewSection=new X(e),this.element=document.createElement("span"),this.element.classList.add("source-code");const t=n.Utils.createShadowRootWithCoreStyles(this.element,{cssFile:[z],delegatesFocus:void 0});this.element.addEventListener("contextmenu",this.contextMenuEventFired.bind(this),!1),t.appendChild(this.customPreviewSection.element())}expandIfPossible(){const e=this.object.customPreview();e&&e.bodyGetterId&&this.customPreviewSection&&this.customPreviewSection.loadBody()}contextMenuEventFired(e){const t=new n.ContextMenu.ContextMenu(e);this.customPreviewSection&&t.revealSection().appendItem(Q(K.showAsJavascriptObject),this.disassemble.bind(this)),t.appendApplicableItems(this.object),t.show()}disassemble(){this.element.shadowRoot&&(this.element.shadowRoot.textContent="",this.customPreviewSection=null,this.element.shadowRoot.appendChild(R.defaultObjectPresentation(this.object)))}}var Z=Object.freeze({__proto__:null,CustomPreviewSection:X,CustomPreviewComponent:q});const ee=new CSSStyleSheet;ee.replaceSync(".object-popover-content{display:block;position:relative;overflow:hidden;flex:1 1 auto}.object-popover-title{text-overflow:ellipsis;overflow:hidden;white-space:nowrap;font-weight:bold;padding-left:18px;padding-bottom:2px}.object-popover-tree{border-top:1px solid var(--color-details-hairline);overflow:auto;width:100%;height:calc(100% - 13px)}.object-popover-container{display:inline-block}\n/*# sourceURL=objectPopover.css */\n");class te{linkifier;resultHighlightedAsDOM;constructor(e,t){this.linkifier=e,this.resultHighlightedAsDOM=t}dispose(){this.resultHighlightedAsDOM&&a.OverlayModel.OverlayModel.hideDOMNodeHighlight(),this.linkifier&&this.linkifier.dispose()}static async buildObjectPopover(e,t){const i=r.StringUtilities.trimEndWithMaxLength(e.description||"",ne);let o=null;if("function"===e.type||"object"===e.type){let s=null,r=!1;if("node"===e.subtype&&(a.OverlayModel.OverlayModel.highlightObjectAsDOMNode(e),r=!0),e.customPreview()){const t=new q(e);t.expandIfPossible(),o=t.element}else{o=document.createElement("div"),o.classList.add("object-popover-content"),t.registerCSSFiles([P,ee]);const n=o.createChild("div","object-popover-title");"function"===e.type?(n.classList.add("source-code"),n.appendChild(R.valueElementForFunctionDescription(e.description))):(n.classList.add("monospace"),n.createChild("span").textContent=i),s=new m.Linkifier.Linkifier;const r=new R(e,"",s,!0);r.element.classList.add("object-popover-tree"),r.titleLessMode(),o.appendChild(r.element)}return o.dataset.stableNameForTest="object-popover-content",t.setMaxContentSize(new n.Geometry.Size(300,250)),t.setSizeBehavior("SetExactSize"),t.contentElement.appendChild(o),new te(s,r)}o=document.createElement("span"),o.dataset.stableNameForTest="object-popover-content",t.registerCSSFiles([P,ee]);const s=o.createChild("span","monospace object-value-"+e.type);return s.style.whiteSpace="pre","string"===e.type?n.UIUtils.createTextChildren(s,`"${i}"`):s.textContent=i,t.contentElement.appendChild(o),new te(null,!1)}}const ne=1e4;var ie=Object.freeze({__proto__:null,ObjectPopoverHelper:te});export{Z as CustomPreviewComponent,j as JavaScriptREPL,ie as ObjectPopoverHelper,G as ObjectPropertiesSection,w as RemoteObjectPreviewFormatter};
